/*
 *说明：命令策略与命令信息关系表 首页脚本
 *
 *@author liuxun 2012-03-19
*/

var opeForm;
var grid;

$(function(){
	opeForm = $('#opeForm');

	grid=$('#listTable').datagrid({
		title: '命令授权列表',
		frozenColumns:[[
            {title:'选择',field:'ck',checkbox:true}
		]],
		columns:[[

            {title:'命令代码',field:'cmd_code',align:'center',width:80},

            {title:'命令值',field:'cmd_value',align:'center',width:80}
        ]],
		pagination:false,
		singleSelect: false
	});

	queryOperation();

//	$('#queryBtn').click(queryOperation);
//	$('#clearBtn').click(clearOperation);
//	$('#reloadBtn').click(refreshWin);
//	$('#addBtn').click(addOperation);
//	$('#editBtn').click(editOperation);
//	$('#deleteBtn').click(deleteOperation);
	$('#okBtn').click(doOk);
	$('#cancelBtn').click(closeWin);
});

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryOperation(){
	var params = opeForm.serializeObject();
	grid.datagrid("options").pageNumber = 1;
	grid.datagrid({
		url: 'D_CMDPOLICY_CMD!queryNotselectedCmdList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//保存按钮操作
function doOk() {

	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中一条记录!');
		return;
	}  
	
	var ids = [];
	for (var i = 0; i < rows.length; i++) {
		ids.push(rows[i].key);
	}
	var params = $ .param({'id' : ids}, true);

	var options = { 
			url: 'D_CMDPOLICY_CMD!doInsertNotselectedCmd.do?' + params,
			type: 'post',
			success: function(data){
				afterOK();
				showInfoWin('操作成功!', refreshWin);
			}
	};

	opeForm.ajaxSubmit(options);
}

//操作成功后刷新列表
function afterOK(){
	queryOperation();
}